import api, { type ResponseData } from '../index'

export default function uploadFile(filePath: string, url: string) {
	return api.upload(url, {
		filePath,
		name: 'file',
		header: {
			// #ifdef PRIVATE
			'X-STORE_PRIVATE_SPHERE_ID':uni.getStorageSync('storeId')
			// #endif
		}
	})
}

export const upload = async (file: File) => {
	return api.upload<ResponseData<{
		url:string,
		name:string,
		domain:string
	}>>('merchant/util/upload', {
		files: [file],
		custom: {
			isLoading: true
		},
		header: {
			// #ifdef PRIVATE
			'X-STORE_PRIVATE_SPHERE_ID':uni.getStorageSync('storeId')
			// #endif
		}
		
	})

}

export const uploadFilePath = async (filePath: string) => {
	return api.upload<ResponseData<{
		url:string,
		name:string,
		domain:string
	}>>('merchant/util/upload', {
		filePath,
		name: 'file',
		header: {
			// #ifdef PRIVATE
			'X-STORE_PRIVATE_SPHERE_ID':uni.getStorageSync('storeId')
			// #endif
		},
		custom: {
			isLoading: true
		}
	})

}
// 批量上传文件
export const uploadFiles = async (filePaths: string[]) => Promise.all(filePaths.map(item => uploadFilePath(item)))